﻿using UnityEngine;
using System.Collections;

public class PlayeController : MonoBehaviour
{
    public float speed;
    public GUIText countText;
    public GUIText winText;
    private int count;

    void Start()
    {
        count = 0;
        SetCount();
        winText.text = "";
    }
    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        rigidbody.AddForce(movement * speed * Time.deltaTime);
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "pickUp")
        {
            other.gameObject.SetActive(false);
            count += 1;
            SetCount();
        }
    }

    private void SetCount()
    {
        countText.text = "Count: " + count.ToString();
        if (count >= 8)
        {
            winText.text = "YOU WIN!";
        }
    }
}
